﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinForm
{
    public partial class HoaDonNhapForm : Form
    {
        public HoaDonNhapForm()
        {
            InitializeComponent();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.MultiSelect = false;
        }

        private void HoaDonNhapForm_Load(object sender, EventArgs e)
        {       
            
        }

        private void dateTimePicker1_CloseUp(object sender, EventArgs e)
        {
            textBox1.Clear();
        }

        private void dateTimePicker2_CloseUp(object sender, EventArgs e)
        {
            textBox1.Clear();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim() != "")
            {
                int id = 0;
                if (!Int32.TryParse(textBox1.Text.Trim(), out id))
                {
                    MessageBox.Show("ID phải là số nguyên");
                    return;
                }
                dataGridView1.DataSource = Library.DAL.HoaDonNhapDAL.FindByID(id);
            }
            else
            {
                dataGridView1.DataSource = Library.DAL.HoaDonNhapDAL.FindByDate(dateTimePicker1.Value, dateTimePicker2.Value);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = Library.DAL.HoaDonNhapDAL.FindAll();
        }

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                Library.BIZ.HoaDonNhapBIZ h;
                h = (Library.BIZ.HoaDonNhapBIZ)dataGridView1.CurrentRow.DataBoundItem;

                if (h == null) return;
                new ChiTietHoaDonNhapForm(h).Show();
            }
            catch
            {
            }
        }
    }
}
